package com.qzw.network.netty.common.util;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author ：quziwei
 * @date ：Created in 2020/6/1 6:18 下午
 * @description：返回值Model
 */
public class Msg<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private String code = Code.SUCCESS.getValue();
    private String msg;
    private Byte dict;

    public Byte getDict() {
        return dict;
    }

    public void setDict(Byte dict) {
        this.dict = dict;
    }

    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public enum Code {

        SUCCESS("000"), FAIL("999"), NO_LOGIN("100"), ERROR("500");

        private String value;

        public String getValue() {
            return value;
        }

        private Code(String value) {
            this.value = value;
        }
    }

    @Override
    public String toString() {
        return "Msg{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", dict=" + dict +
                ", data=" + data +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Msg<?> msg1 = (Msg<?>) o;
        return Objects.equals(code, msg1.code) &&
                Objects.equals(msg, msg1.msg) &&
                Objects.equals(dict, msg1.dict) &&
                Objects.equals(data, msg1.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, msg, dict, data);
    }
}
